
import redis
__author__ = 'mleaf'


class RedisWs:
    def __init__(self):
        self.r = redis.Redis('localhost', port=6379, db=1)

    def set(self, key, value, expire=10):
        self.r.set(key, value)
        # self.r.expire(key, expire)

    def get(self, key):
        value = self.r.get(key)
        if value:
            return value.decode()
        else:
            return None

    def renew(self, key, expire=10):
        self.r.expire(key, expire)

    def hset(self, name, key, value, expire=10):
        self.r.hset(name, key, value)
        self.r.expire(name, expire)

    def hget(self, name, key):
        value = self.r.hget(name, key)
        if value:
            return value.decode()
        else:
            return None

r_ws = RedisWs()
